:root {
    --primary-color: #2196F3;
    --secondary-color: #E3F2FD;
    --text-color: #333;
    --light-text: #666;
    --border-color: #E0E0E0;
    --success-color: #4CAF50;
    --error-color: #F44336;
    --background-color: #F5F5F5;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--background-color);
    color: var(--text-color);
    line-height: 1.6;
}

/* 登录面板样式优化 */
#loginPanel {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    background: linear-gradient(135deg, var(--primary-color), #1976D2);
    position: relative;
    overflow: hidden;
}

#loginPanel::before {
    content: '';
    position: absolute;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 60%);
    animation: rotate 20s linear infinite;
}

.login-container {
    background: rgba(255, 255, 255, 0.95);
    padding: 2.5rem;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.1);
    width: 100%;
    max-width: 400px;
    position: relative;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255,255,255,0.2);
}

.login-container h1 {
    color: var(--primary-color);
    text-align: center;
    margin-bottom: 2rem;
    font-size: 2rem;
    font-weight: 600;
}

.login-container input {
    width: 100%;
    padding: 1rem;
    border: 2px solid rgba(0,0,0,0.1);
    border-radius: 12px;
    font-size: 1rem;
    transition: all 0.3s ease;
    margin-bottom: 1.5rem;
}

.login-container input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(33,150,243,0.1);
    outline: none;
}

.login-container button {
    width: 100%;
    padding: 1rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
}

.login-container button:hover {
    background: #1976D2;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

/* 聊天面板样式 */
#chatPanel {
    display: grid;
    grid-template-columns: 300px 1fr;
    grid-template-rows: 60px 1fr;
    height: 100vh;
    background: white;
}

/* 头部栏样式 */
.header {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    background: var(--primary-color);
    color: white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    height: 60px;
}

.current-user {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.9);
    color: var(--primary-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 1.1rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.user-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    opacity: 0.9;
}

.user-status i {
    font-size: 0.8rem;
    color: #4CAF50;
}

/* 侧边栏样式 */
.sidebar {
    grid-row: 2;
    border-right: 1px solid var(--border-color);
    background: white;
    display: flex;
    flex-direction: column;
}

.search-container {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}

#userSearch {
    width: 100%;
    padding: 0.8rem;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    outline: none;
    font-size: 0.9rem;
}

#userSearch:focus {
    border-color: var(--primary-color);
}

.user-list {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0;
}

.user-item {
    display: flex;
    align-items: center;
    padding: 1rem;
    gap: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    border-radius: 12px;
    margin: 0.2rem 0.5rem;
}

.user-item:hover {
    background-color: var(--secondary-color);
    transform: translateX(4px);
}

.user-item.selected {
    background-color: var(--secondary-color);
    position: relative;
}

.user-item.selected::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: var(--primary-color);
    border-radius: 4px;
}

.user-item .user-avatar {
    width: 40px;
    height: 40px;
    background: var(--primary-color);
    color: white;
    font-size: 1.2rem;
    border-radius: 12px;
    transition: all 0.2s ease;
}

.user-item:hover .user-avatar {
    transform: scale(1.05);
}

/* 聊天区域样式 */
.chat-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 60px); /* 减去头部高度 */
    background: white;
}

.chat-container::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 20px;
    background: linear-gradient(to top, 
        rgba(0,0,0,0.05) 0%,
        transparent 100%);
    pointer-events: none;
}

.chat-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    font-weight: bold;
}

#messageArea {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    scroll-behavior: smooth;
    height: calc(100vh - 180px); /* 减去头部和输入框高度 */
    max-height: calc(100vh - 180px);
}

.message {
    display: flex;
    flex-direction: column;
    max-width: 70%;
    margin-bottom: 1rem;
    animation: fadeIn 0.3s ease-out;
    position: relative;
}

.message.sent {
    align-self: flex-end;
}

.message.received {
    align-self: flex-start;
}

.message-content {
    padding: 1rem 1.2rem;
    border-radius: 16px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    word-wrap: break-word;
    position: relative;
    z-index: 1;
    line-height: 1.5;
    transition: all 0.2s ease;
}

.sent .message-content {
    background: linear-gradient(135deg, var(--primary-color), #1976D2);
    color: white;
    border-bottom-right-radius: 4px;
    margin-left: auto;
}

.received .message-content {
    background: white;
    border-bottom-left-radius: 4px;
    margin-right: auto;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.time {
    font-size: 0.75rem;
    color: var(--light-text);
    margin-top: 0.3rem;
    opacity: 0.8;
}

.sent .time {
    text-align: right;
    margin-left: auto;
}

.message-status {
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-top: 0.3rem;
    color: var(--light-text);
    transition: all 0.2s ease;
}

.sent .message-status {
    margin-left: auto;
    padding-right: 0.2rem;
}

.status-icon {
    font-size: 0.85rem;
    display: flex;
    align-items: center;
}

/* 发送中状态 */
.sending .status-text {
    color: var(--light-text);
}

.sending .status-icon {
    animation: spin 1s linear infinite;
}

/* 已发送状态 */
.sent .status-text {
    color: var(--success-color);
    opacity: 0.7;
}

.sent .status-icon {
    color: var(--success-color);
    opacity: 0.7;
}

/* 已送达状态 */
.delivered .status-text {
    color: var(--success-color);
    opacity: 0.85;
}

.delivered .status-icon {
    color: var(--success-color);
    opacity: 0.85;
}

/* 已读状态 */
.read .status-text {
    color: var(--primary-color);
    font-weight: 500;
}

.read .status-icon {
    color: var(--primary-color);
    transform: scale(1.1);
}

.read .status-icon i {
    opacity: 1;
}

/* 双重对勾效果 */
.delivered .status-icon,
.read .status-icon {
    position: relative;
}

.delivered .status-icon i:last-child,
.read .status-icon i:last-child {
    position: absolute;
    left: -3px;
    opacity: 0.7;
}

.read .status-icon i:last-child {
    opacity: 0.9;
}

/* 状态切换动画 */
@keyframes statusFadeIn {
    from {
        opacity: 0;
        transform: translateY(2px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-status {
    animation: statusFadeIn 0.2s ease-out;
}

/* 状态变化时的过渡效果 */
.status-text,
.status-icon {
    transition: all 0.3s ease;
}

/* 已读状态的特殊动画 */
@keyframes readAnimation {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.2);
    }
    100% {
        transform: scale(1);
    }
}

.read .status-icon {
    animation: readAnimation 0.3s ease-out;
}

/* 输入区域样式优化 */
.input-container {
    display: flex;
    align-items: flex-end;
    gap: 1rem;
    padding: 1.2rem;
    background: white;
    border-top: 1px solid rgba(0,0,0,0.08);
    position: relative;
}

#messageInput {
    flex: 1;
    padding: 0.8rem 1.2rem;
    border: 2px solid rgba(0,0,0,0.08);
    border-radius: 24px;
    font-size: 0.95rem;
    line-height: 1.5;
    resize: none;
    transition: all 0.3s ease;
    min-height: 44px;
    max-height: 120px;
    background: var(--background-color);
    color: var(--text-color);
    font-family: inherit;
}

#messageInput:focus {
    border-color: var(--primary-color);
    background: white;
    box-shadow: 0 2px 8px rgba(33, 150, 243, 0.15);
    outline: none;
}

#messageInput::placeholder {
    color: #999;
    font-size: 0.95rem;
}

.send-button {
    padding: 0;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--primary-color);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    flex-shrink: 0;
    box-shadow: 0 2px 6px rgba(33, 150, 243, 0.2);
}

.send-button:hover:not(:disabled) {
    transform: translateY(-2px);
    background: #1976D2;
    box-shadow: 0 4px 12px rgba(33, 150, 243, 0.3);
}

.send-button:active:not(:disabled) {
    transform: translateY(0);
}

.send-button:disabled {
    background-color: var(--border-color);
    cursor: not-allowed;
    box-shadow: none;
    opacity: 0.7;
}

.send-button i {
    font-size: 1.2rem;
    transition: transform 0.3s ease;
}

.send-button:hover:not(:disabled) i {
    transform: translateX(2px);
}

/* 输入框自动调整高度的动画 */
#messageInput {
    overflow-y: hidden;
    transition: height 0.2s ease;
}

/* 添加输入框聚焦时的背景过渡效果 */
.input-container::before {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 100%;
    background: linear-gradient(to top, 
        rgba(255,255,255,1) 0%,
        rgba(255,255,255,0.8) 100%);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.input-container:focus-within::before {
    opacity: 1;
}

/* 添加输入框底部的阴影效果 */
.chat-container {
    position: relative;
}

.chat-container::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 20px;
    background: linear-gradient(to top, 
        rgba(0,0,0,0.05) 0%,
        transparent 100%);
    pointer-events: none;
}

/* 系统消息样式 */
.system-message {
    text-align: center;
    color: var(--light-text);
    margin: 1rem 0;
    font-size: 0.85rem;
    opacity: 0.8;
    padding: 0.5rem 1rem;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 20px;
    display: inline-block;
    margin-left: 50%;
    transform: translateX(-50%);
    animation: fadeIn 0.3s ease-out;
}

/* 动画效果 */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-new {
    animation: fadeIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* 响应式设计 */
@media (max-width: 768px) {
    #chatPanel {
        grid-template-columns: 1fr;
    }

    .sidebar {
        display: none;
    }

    .sidebar.active {
        display: flex;
        position: fixed;
        left: 0;
        top: 60px;
        bottom: 0;
        width: 100%;
        z-index: 100;
    }

    .message {
        max-width: 85%;
    }
}

/* 退出按钮样式 */
.logout-button {
    padding: 0.5rem 1rem;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.logout-button:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-1px);
}

.logout-button i {
    font-size: 1rem;
}

/* 消息气泡悬停效果 */
.message-content:hover {
    transform: translateY(-1px);
    transition: transform 0.2s ease;
}

/* 动画效果 */
@keyframes rotate {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-10px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.user-item {
    animation: slideIn 0.3s ease-out;
}

/* 加载历史消息提示样式 */
.loading-history {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    gap: 0.5rem;
    color: var(--light-text);
    font-size: 0.9rem;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 12px;
    margin: 1rem auto;
    width: fit-content;
}

.loading-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--primary-color);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* 消息加载动画 */
.message {
    opacity: 0;
    transform: translateY(10px);
    animation: messageAppear 0.3s ease forwards;
}

@keyframes messageAppear {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* 添加滚动条样式 */
#messageArea::-webkit-scrollbar {
    width: 6px;
}

#messageArea::-webkit-scrollbar-track {
    background: transparent;
}

#messageArea::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 3px;
}

#messageArea::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.2);
}

/* 聊天面板布局 */
.chat-area {
    display: flex;
    flex-direction: column;
    height: 100vh; /* 使用视口高度 */
    max-height: 100vh;
}

/* 消息区域 */
#messageArea {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    /* 添加平滑滚动 */
    scroll-behavior: smooth;
    /* 保持一定距离以显示新消息提示 */
    scroll-padding-bottom: 20px;
}

/* 输入区域固定在底部 */
.input-area {
    position: sticky;
    bottom: 0;
    background: #fff;
    padding: 1rem;
    border-top: 1px solid #eee;
    display: flex;
    gap: 10px;
}

#messageInput {
    flex: 1;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    resize: none;
    min-height: 40px;
    max-height: 120px; /* 限制输入框最大高度 */
}

.send-button {
    padding: 8px 16px;
    background: #007bff;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

/* 新消息提示 */
.new-message-indicator {
    position: fixed;
    bottom: 70px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 123, 255, 0.9);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    display: none;
    z-index: 1000;
}

/* 消息样式 */
.message {
    margin: 8px 0;
    max-width: 80%;
    word-wrap: break-word;
}

.message.sent {
    margin-left: auto;
}

.message.received {
    margin-right: auto;
}

.input-area {
    padding: 1rem;
    background: white;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 0.5rem;
    min-height: 60px;
}

#messageInput {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    resize: none;
    max-height: 100px;
}